<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('角色列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>户编号：</label>
                            <input type="text" name="fid"/>
                        </li>
                        <li>
                            <label>姓名：</label>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <label>自然村：</label>
                            <select name="natVillage" th:with="type=${@dict.getType('base_nature_village')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:role:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:role:remove')}]];
    var natVillageDatas = [[${@dict.getType('base_nature_village')}]];
    var returnToPovertyDatas = [[${@dict.getType('return_to_poverty')}]];
    var prefix = ctx + "system/average_income_info";
    var checkPrefix = ctx + "system/info/check/{id}"
    var editPrefix = ctx + "system/info/edit/{id}"

    $(function () {
        var options = {
            url: prefix + "/list",
            modalName: "农户收入信息对比",
            updateUrl: editPrefix,
            columns: [{
                checkbox: true
            },
                {
                    field: 'fid',
                    title: '户编号',
                    //sortable: true
                },
                {
                    field: 'name',
                    title: '姓名',
                    //sortable: true
                },
                {
                    field: 'idCard',
                    title: '证件号码',
                    //sortable: true
                },
                {
                    field: 'natVillage',
                    title: '自然村',
                    //sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(natVillageDatas, value);
                    }
                },
                {
                    field: 'avgIncome',
                    title: '本年人均收入（元）',
                    //sortable: true
                    formatter(value, row, index) {
                        var str = value.toString();
                        if (str.indexOf('.') == -1) {
                            return str + ".00";
                        } else if (str.indexOf('.') == str.length - 2) {
                            return str + "0";
                        } else return str;
                    }
                },
                {
                    field: 'lastAvgIncome',
                    title: '上一年人均收入（元）',
                    formatter(value, row, index) {
                        var str = value.toString();
                        if (str.indexOf('.') == -1) {
                            return str + ".00";
                        } else if (str.indexOf('.') == str.length - 2) {
                            return str + "0";
                        } else return str;
                    }
                    //sortName:'avgIncome',
                    //sortable: true
                },
                {
                    field: 'isBackIntoPoverty',
                    title: '是否返贫',
                    //sortable: true,
                    formatter: function (value, row, index) {
                        if (value == 1) {
                            return "<span style='color:red'>返贫</span>"
                        } else {
                            return "<span>未返贫</span>"
                        }
                        // return $.table.selectDictLabel(returnToPovertyDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        var tmp = row.isBackIntoPoverty.toString();
                        //actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if (tmp == "1")
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        else actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="submit(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        return actions.join('');
                    }
                }]
        }
        $.table.init(options);
    });

    function submit(id) {
        var url = checkPrefix.replace("{id}", id);
        $.modal.parentTab("查看", url);
    }
</script>
</body>
</html>
